<?php
session_start();

include(substr($_SERVER['SCRIPT_FILENAME'],0,-20).'stationInfo.php');
include('../config.php');


//Get Data		
$myTimeStamp = $_SESSION['log_timestamp'];
//$_SESSION['merged_array']



define('FPDF_FONTPATH','font/');
require_once('fpdf.php');


$pdf=new FPDF();

function description($type){ //write a description in front of PSA's and SPA's
	if($type == 'PSA' || $type == 'EPSA'){
		return "PSA: ";
	}elseif($type == 'UW'){
		return "UW CREDIT: ";
	}
}


//Setup Pages for programs
$pdf->AddPage();
$pdf->SetFont('Arial','B',13);
//Create Header for Cover Page
$pdf->Cell(0,6,strtoupper($stationID)."-FM $city, $state",0,1,'C',0);
$pdf->Cell(0,6,date("l F j, Y",$_SESSION['log_timestamp']),0,1,'C',0);
$pdf->Cell(0,6,'Daily Program Log',0,1,'C',0);
$pdf->Cell(0,6,"",0,1,'C',0);
//First Page Colum Header
$pdf->SetFont('Arial','',12);
$pdf->Cell(50,6,'Actual Time Schduled',B,0,'L',0);
$pdf->Cell(100,6,'Program Title',B,0,'L',0);
$pdf->Cell(20,6,'Source',B,0,'L',0);
$pdf->Cell(18,6,'Type',B,1,'L',0);
$pdf->Cell(0,2,"",0,1,'C',0);



$pdf->SetAutoPageBreak(1,6);

$cellHeight = '10';
$L = 0;
for($i=0; $i < count($_SESSION['merged_array']); $i++){


//if set to inactive, don't print row
if($_SESSION['merged_array'][$i]['active'] == 'false'){
-$L; 
	continue; 
}


			if($_SESSION['merged_array'][$i]['source'] == 'Other'){
				if($_SESSION['merged_array'][$i]['source_other'] == ""){
					$source = 'Other';
				}else{
					$source = $_SESSION['merged_array'][$i]['source_other'];
				}
			}else{
				$source = $_SESSION['merged_array'][$i]['source'];
			}
			
			
			if($_SESSION['merged_array'][$i]['type'] == 'Other'){
				if($_SESSION['merged_array'][$i]['type_other'] == ""){
					$type = 'Other';
				}else{
					$type = $_SESSION['merged_array'][$i]['type_other'];
				}
			}else{
				$type = $_SESSION['merged_array'][$i]['type'];
			}


 

			if($type =="&nbsp;" || $type =="&nbsp"){
				$type = "";
			}
			
			if($source =="&nbsp;"){
				$source = "";
			}


		if($_SESSION['merged_array'][$i]['title'] == "&nbsp;"){
			$title = "";
		}else{
			$title = $_SESSION['merged_array'][$i]['title'];
		}
		


$time = date("h",mktime ((str_replace (":", ",", $_SESSION['merged_array'][$i]['military'])),0,0,0)).":". substr($_SESSION['merged_array'][$i]['military'], 3, 5)  . " " .date("a",mktime ((str_replace (":", ",", $_SESSION['merged_array'][$i]['military'])),0,0,0));

	//GENERATE PROGRAM LISTINGS
	if($L&1){
		$pdf->SetFillColor(174,174,174);
	}else{
		$pdf->SetFillColor(255,255,255);
	}
	$pdf->Cell(16,"$cellHeight",'',B,0,'L',0);
	$pdf->Cell(1,"$cellHeight",'',0,0,'L',0);
	$pdf->Cell(25,"$cellHeight",$time,0,0,'L',1);//time
	$pdf->Cell(8,"$cellHeight",'',0,0,'L',1);
	
	//Program Title
	if(!$_SESSION['merged_array'][$i]['ID']){//we have a Spot - bold Font
	
		if($_SESSION['merged_array'][$i]['live'] == 'true'){
			$live = " - LIVE";
		}else{
			$live = "";
		}
	
	
	
	
		$pdf->SetFont('Arial','B',12);
		$pdf->Cell(100,"$cellHeight","".description($_SESSION['merged_array'][$i]['type']) . stripslashes($_SESSION['merged_array'][$i]['spotID']).$live." (:" . round($_SESSION['merged_array'][$i]['length']).")",0,0,'L',1);//title 
		$pdf->Cell(21,"$cellHeight",'AV',0,0,'L',1);//source
		$pdf->Cell(15,"$cellHeight",$_SESSION['merged_array'][$i]['type'],0,1,'L',1);//Type
		$pdf->SetFont('Arial','',12);
	}elseif($_SESSION['merged_array'][$i]['type'] == 'ID'){//We have a station ID
		$pdf->Cell(100,"$cellHeight",stripslashes($title),0,0,'L',1);//title
		$pdf->Cell(21,"$cellHeight",$source,0,0,'L',1);//source
		$pdf->Cell(15,"$cellHeight",$type,0,1,'L',1);//Type	
	}elseif($_SESSION['merged_array'][$i]['type'] == 'PSA'){//We have a program
		$pdf->SetFont('Arial','U',12);
		$pdf->Cell(100,"$cellHeight","PSA: ".stripslashes($title),0,0,'L',1);//title
		$pdf->SetFont('Arial','',12);
		$pdf->Cell(21,"$cellHeight",$source,0,0,'L',1);//source
		$pdf->Cell(15,"$cellHeight",$type,0,1,'L',1);//Type	
	}elseif($_SESSION['merged_array'][$i]['type'] == 'SPA'){//We have a program
		$pdf->SetFont('Arial','U',12);
		$pdf->Cell(100,"$cellHeight","SPA: ".stripslashes($title),0,0,'L',1);//title
		$pdf->SetFont('Arial','',12);
		$pdf->Cell(21,"$cellHeight",$source,0,0,'L',1);//source
		$pdf->Cell(15,"$cellHeight",$type,0,1,'L',1);//Type	
	}else{//We have a program
		$pdf->SetFont('Arial','U',12);
		$pdf->Cell(100,"$cellHeight",stripslashes($title),0,0,'L',1);//title
		$pdf->SetFont('Arial','',12);
		$pdf->Cell(21,"$cellHeight",$source,0,0,'L',1);//source
		$pdf->Cell(15,"$cellHeight",$type,0,1,'L',1);//Type	
	}



++$L;
}

$pdf->Output(); 
?>
